package com.mijie.core;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Paging<T> {

	private static final int DEFAULT_PAGESIZE = 20;
	private long rows ;		//总行数
	private int pageCount;	//总页数
	private int pageNum;	//当前页数
	private int pageSize;	//每页显示条数
	private int offset;
	private List<T> list;
	
	public Paging(){
		this(DEFAULT_PAGESIZE);
	}
	
	public Paging(int pageSize){
		this.offset = 0;
		this.pageSize = pageSize;
		this.list = new ArrayList<T>(pageSize);
	}
	
	public void reset(){
		this.rows = 0;
		this.pageCount = 0;
		this.pageNum = 0;
		this.offset = 0;
		this.list = Collections.emptyList();
	}
	
	public boolean hasNext() {
		return (pageNum + 1 <= pageCount);
	}
	
	public boolean hasPreviou() {
		return (pageNum - 1 >= 1);
	}
	
	public int getNextNum() {
		return hasNext() ? pageNum + 1 : pageNum;
	}

	public int getPreviouNum() {
		return hasPreviou() ? pageNum - 1 : pageNum;
	}
	
	public long getRows() {
		return rows;
	}

	public void setRows(long rows) {
		this.rows = rows;
	}

	public long getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getOffset() {
		return offset;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public void setOffset(int offset) {
		this.offset = offset;
	}

	@Override
	public String toString() {
		return "Paging [rows=" + rows + ", pageCount=" + pageCount
				+ ", pageNum=" + pageNum + ", pageSize=" + pageSize
				+ ", offset=" + offset + "]";
	}
	
}
